home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-14 | 5.9 KB | 120 lines | [TEXT/CCL2] |
- (in-package ccl)
-
- (let ((*warn-if-redefine-kernel* nil))
- ; Tests to see if a handler exists for the given apple event. - NJW 8/1/94
- (defun get-handler (theAppleEvent)
- (handler-bind ((error #'(lambda (x) (declare (ignore x)) nil)))
- (let* ((class (ae-get-attribute-type theAppleEvent #$keyEventClassAttr))
- (id (ae-get-attribute-type theAppleEvent #$keyEventIDAttr))
- (id-table (gethash class %appleevent-handlers%)))
- (unless id-table
- (setq id-table (gethash :|****| %appleevent-handlers%)))
- (and id-table (gethash id id-table)))))
-
-
- ; defer-appleevent-handler is handles all appleevents & simply suspends the event
- ; and appends the cons of the event, reply, and refcon to *deferred-appleevents*
- ; If the event is from MCL itself, it handles it right away.
-
-
- (defpascal defer-appleevent-handler (:pointer theAppleEvent :pointer reply
- :long handlerRefcon :word)
- (declare (ignore handlerRefcon))
- (rlet ((source :word)
- (actualType :long)
- (actualSize :long))
- (if (or *inside-aesend*
- (and
- (eql #$noErr (#_AEGetAttributePtr
- theAppleEvent #$keyEventSourceAttr #$TypeShortInteger
- actualType source 2 actualSize))
- (let ((source (%get-word source)))
- (or (eql #$kAESameProcess source)
- (eql #$kAEDirectCall source)
- ; If handler doesn't exist then don't suspend. Otherwise AppleScript
- ; gets confused. - NJW 8/1/94
- (null (get-handler theAppleEvent))))))
- (do-appleevent theAppleEvent reply nil)
- (progn
- (ae-error (#_AESuspendTheCurrentEvent theAppleEvent))
- (setq *deferred-appleevents*
- (nconc *deferred-appleevents*
- (cheap-cons (cheap-cons (copy-record theAppleEvent :aedesc)
- (copy-record reply :aedesc))
- nil)))
- ; I'm not absolutely sure that this is the correct result in this case,
- ; but we will assume it is. - NJW 8/1/94
- #$noErr))))
-
- ; (mcl 2.0p2)
- (defun do-appleevent (theAppleEvent reply deferred-p)
- (let ((result #$noErr)
- (class nil)
- (id nil)
- (resumed? nil)
- (handler nil))
- (block buck-stops-here ; don't throw past here unless (and
- ; deferred-p *signal-applevent-errors*)
- (labels ((resume-appleevent ()
- (unless resumed?
- (setq resumed? t)
- ; try to put the result code in the reply (the reply may be null)
- ; if the event is itself a reply!
- ; The following line was removed since it causes
- ; AEProcessAppleEvent to fail when
- ; the AppleEvent is an AppleScript Scripting Addition. MCL
- ; should not be adding to the reply if it doesn't handle the
- ; event. - NJW 7/27/94
- (if handler
- (ae-put-parameter-longinteger reply #$keyErrorNumber result nil))
- (when deferred-p
- (#_AEResumeTheCurrentEvent theAppleEvent reply
- (%int-to-ptr #$kAENoDispatch) 0)
- (dispose-record theAppleEvent)
- (dispose-record reply)
- (when *appleevent-quit*
- (setq *appleevent-quit* nil) ; don't repeat if aborted out
- (quit)))))
- (error-handler (c)
- ; Removed based on the principle as in resume-appleevent. However, this
- ; addition does not stop AEProcessAppleEvent, possibly because it is effecting
- ; 'theAppleEvent' rather than 'reply'. - NJW 7/27/94
- (if handler
- (ae-put-parameter-char theAppleEvent #$keyErrorString
- (with-output-to-string (s)
- (report-condition c s))
- nil))
- (if (typep c 'appleevent-error)
- (setq result (oserr c)) ; return the error to the AppleEvent Manager
- (setq result #$errAEEventNotHandled))
- (resume-appleevent)
- (unless (and deferred-p *signal-appleevent-errors*)
- (when *report-appleevent-errors*
- (format *error-output* "~%> Error while handling AppleEvent: '~a' '~a'~%> "
- class id)
- (report-condition c *error-output*))
- (return-from buck-stops-here))))
- (declare (dynamic-extent #'resume-appleevent #'error-handler))
- (unwind-protect ; make sure we resume the AppleEvent if deferred-p
- (handler-bind ((error #'error-handler))
- (setq class (ae-get-attribute-type theAppleEvent
- #$keyEventClassAttr)
- id (ae-get-attribute-type theAppleEvent #$keyEventIDAttr))
- (let ((id-table (gethash class %appleevent-handlers%)))
- (unless id-table
- (setq id-table (gethash :|****| %appleevent-handlers%)))
- (setq handler (and id-table (gethash id id-table)))
- (unless handler
- (error (make-condition 'appleevent-error :oserr #$errAEEventNotHandled
- :error-string (format nil "No Lisp Handler for '~a' '~a'"
- class id))))
- (funcall (car handler) *application* theAppleEvent reply (cdr handler))))
- (resume-appleevent)
- (unless (and deferred-p *signal-appleevent-errors*)
- (return-from buck-stops-here)))))
- result))
- )
-
-
-
-